package chapter2;

import java.io.*;

public class IO_1 {
    public static void main(String[] args) {
        //TODO Java IO文件复制
        //TODO  数据源文件对象
        File srcFile = new File("D:\\java\\untitled\\src\\chapter2\\test");
        File destFile = new File("D:\\java\\untitled\\src\\chapter2\\test.copy");
        //TODO 文件输入流（管道对象）
        FileInputStream in = null;
        //TODO 文件输出流（管道对象）
        FileOutputStream out = null;

        try {
            in = new FileInputStream(srcFile);
            out = new FileOutputStream(destFile);
            //  TODO 打开阀门，流转数据(输入)
            int data = in.read();
            //  TODO 打开阀门，流转数据（输出）
            out.write(data);
        }catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(in != null) {
                try {
                    in.close();
                }catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if(out != null) {
                try {
                    out.close();
                }catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }


}
